package com.seu.me.thread.day1.sync005;

/**
 * synchronized异常
 *
 * @author liangfeihu
 */
public class SyncException {
    private int i = 0;

    public synchronized void operation() {
        while (true) {
            try {
                i++;
                Thread.sleep(100);
                System.out.println(Thread.currentThread().getName() + " , i = " + i);
                if (i == 5) {
                    Integer.parseInt("a");
                    //throw new RuntimeException();
                }
                if (i == 10) {
                    break;
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }/* catch (RuntimeException e) {
                System.out.println("----------------start-------------------");
                e.printStackTrace();
                System.out.println("-----------------end--------------------");
            }*/
        } // end while
    }

    public static void main(String[] args) {
        final SyncException se = new SyncException();

        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                se.operation();
            }
        }, "t1");

        t1.start();
    }

}
